
<!DOCTYPE html>

<html>
  
<!-- Mirrored from docs.sympy.org/latest/modules/physics/units/quantities.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:27:50 GMT -->
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

    <title>Physical quantities &#8212; SymPy 1.9 documentation</title>
    <link rel="stylesheet" type="text/css" href="../../../_static/pygments.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/default.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/graphviz.css" />
    <link rel="stylesheet" type="text/css" href="../../../_static/plot_directive.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-core.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-autocomplete.css" />
    <link rel="stylesheet" type="text/css" href="../../../../../live.sympy.org/static/live-sphinx.css" />
    
    <script data-url_root="../../../" id="documentation_options" src="../../../_static/documentation_options.js"></script>
    <script src="../../../_static/jquery.js"></script>
    <script src="../../../_static/underscore.js"></script>
    <script src="../../../_static/doctools.js"></script>
    <script src="../../../../../live.sympy.org/static/utilities.js"></script>
    <script src="../../../../../live.sympy.org/static/external/classy.js"></script>
    <script src="../../../../../live.sympy.org/static/live-core.js"></script>
    <script src="../../../../../live.sympy.org/static/live-autocomplete.js"></script>
    <script src="../../../../../live.sympy.org/static/live-sphinx.js"></script>
    
    <link rel="shortcut icon" href="../../../_static/sympy-notailtext-favicon.ico"/>
    <link href="quantities.html" rel="canonical" />
    
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" />
    <link rel="next" title="High energy physics" href="../hep/index.html" />
    <link rel="prev" title="Units and unit systems" href="unitsystem.html" /> 
  </head><body>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../hep/index.html" title="High energy physics"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="unitsystem.html" title="Units and unit systems"
             accesskey="P">previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../index.html" >Physics</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="index.html" accesskey="U">Unit systems</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Physical quantities</a></li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body" role="main">
            
  <section id="module-sympy.physics.units.quantities">
<span id="physical-quantities"></span><h1>Physical quantities<a class="headerlink" href="#module-sympy.physics.units.quantities" title="Permalink to this headline">¶</a></h1>
<p>Physical quantities.</p>
<dl class="py class">
<dt class="sig sig-object py" id="sympy.physics.units.quantities.Quantity">
<em class="property"><span class="pre">class</span> </em><span class="sig-prename descclassname"><span class="pre">sympy.physics.units.quantities.</span></span><span class="sig-name descname"><span class="pre">Quantity</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">name</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">abbrev</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">dimension</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">scale_factor</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">latex_repr</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pretty_unicode_repr</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">pretty_ascii_repr</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">mathml_presentation_repr</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">**</span></span><span class="n"><span class="pre">assumptions</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/units/quantities.py#L11-L211"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.units.quantities.Quantity" title="Permalink to this definition">¶</a></dt>
<dd><p>Physical quantity: can be a unit of measure, a constant or a generic quantity.</p>
<dl class="py property">
<dt class="sig sig-object py" id="sympy.physics.units.quantities.Quantity.abbrev">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">abbrev</span></span><a class="headerlink" href="#sympy.physics.units.quantities.Quantity.abbrev" title="Permalink to this definition">¶</a></dt>
<dd><p>Symbol representing the unit name.</p>
<p>Prepend the abbreviation with the prefix symbol if it is defines.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.physics.units.quantities.Quantity.convert_to">
<span class="sig-name descname"><span class="pre">convert_to</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">other</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">unit_system</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'SI'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/units/quantities.py#L188-L206"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.units.quantities.Quantity.convert_to" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert the quantity to another quantity of same dimensions.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.units</span> <span class="kn">import</span> <span class="n">speed_of_light</span><span class="p">,</span> <span class="n">meter</span><span class="p">,</span> <span class="n">second</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">speed_of_light</span>
<span class="go">speed_of_light</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">speed_of_light</span><span class="o">.</span><span class="n">convert_to</span><span class="p">(</span><span class="n">meter</span><span class="o">/</span><span class="n">second</span><span class="p">)</span>
<span class="go">299792458*meter/second</span>
</pre></div>
</div>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.units</span> <span class="kn">import</span> <span class="n">liter</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">liter</span><span class="o">.</span><span class="n">convert_to</span><span class="p">(</span><span class="n">meter</span><span class="o">**</span><span class="mi">3</span><span class="p">)</span>
<span class="go">meter**3/1000</span>
</pre></div>
</div>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.physics.units.quantities.Quantity.free_symbols">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">free_symbols</span></span><a class="headerlink" href="#sympy.physics.units.quantities.Quantity.free_symbols" title="Permalink to this definition">¶</a></dt>
<dd><p>Return free symbols from quantity.</p>
</dd></dl>

<dl class="py property">
<dt class="sig sig-object py" id="sympy.physics.units.quantities.Quantity.scale_factor">
<em class="property"><span class="pre">property</span> </em><span class="sig-name descname"><span class="pre">scale_factor</span></span><a class="headerlink" href="#sympy.physics.units.quantities.Quantity.scale_factor" title="Permalink to this definition">¶</a></dt>
<dd><p>Overall magnitude of the quantity as compared to the canonical units.</p>
</dd></dl>

<dl class="py method">
<dt class="sig sig-object py" id="sympy.physics.units.quantities.Quantity.set_global_relative_scale_factor">
<span class="sig-name descname"><span class="pre">set_global_relative_scale_factor</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">scale_factor</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">reference_quantity</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/units/quantities.py#L99-L112"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.units.quantities.Quantity.set_global_relative_scale_factor" title="Permalink to this definition">¶</a></dt>
<dd><p>Setting a scale factor that is valid across all unit system.</p>
</dd></dl>

</dd></dl>

<section id="module-sympy.physics.units.util">
<span id="conversion-between-quantities"></span><h2>Conversion between quantities<a class="headerlink" href="#module-sympy.physics.units.util" title="Permalink to this headline">¶</a></h2>
<p>Several methods to simplify expressions involving unit objects.</p>
<dl class="py function">
<dt class="sig sig-object py" id="sympy.physics.units.util.convert_to">
<span class="sig-prename descclassname"><span class="pre">sympy.physics.units.util.</span></span><span class="sig-name descname"><span class="pre">convert_to</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">expr</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">target_units</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">unit_system</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">'SI'</span></span></em><span class="sig-paren">)</span><a class="reference external" href="https://github.com/sympy/sympy/blob/00d6469eafdd4aac346a0b598184c15f2560dbe5/sympy/physics/units/util.py#L44-L116"><span class="viewcode-link"><span class="pre">[source]</span></span></a><a class="headerlink" href="#sympy.physics.units.util.convert_to" title="Permalink to this definition">¶</a></dt>
<dd><p>Convert <code class="docutils literal notranslate"><span class="pre">expr</span></code> to the same expression with all of its units and quantities
represented as factors of <code class="docutils literal notranslate"><span class="pre">target_units</span></code>, whenever the dimension is compatible.</p>
<p><code class="docutils literal notranslate"><span class="pre">target_units</span></code> may be a single unit/quantity, or a collection of
units/quantities.</p>
<p class="rubric">Examples</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.units</span> <span class="kn">import</span> <span class="n">speed_of_light</span><span class="p">,</span> <span class="n">meter</span><span class="p">,</span> <span class="n">gram</span><span class="p">,</span> <span class="n">second</span><span class="p">,</span> <span class="n">day</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.units</span> <span class="kn">import</span> <span class="n">mile</span><span class="p">,</span> <span class="n">newton</span><span class="p">,</span> <span class="n">kilogram</span><span class="p">,</span> <span class="n">atomic_mass_constant</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.units</span> <span class="kn">import</span> <span class="n">kilometer</span><span class="p">,</span> <span class="n">centimeter</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.units</span> <span class="kn">import</span> <span class="n">gravitational_constant</span><span class="p">,</span> <span class="n">hbar</span>
<span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">sympy.physics.units</span> <span class="kn">import</span> <span class="n">convert_to</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">convert_to</span><span class="p">(</span><span class="n">mile</span><span class="p">,</span> <span class="n">kilometer</span><span class="p">)</span>
<span class="go">25146*kilometer/15625</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">convert_to</span><span class="p">(</span><span class="n">mile</span><span class="p">,</span> <span class="n">kilometer</span><span class="p">)</span><span class="o">.</span><span class="n">n</span><span class="p">()</span>
<span class="go">1.609344*kilometer</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">convert_to</span><span class="p">(</span><span class="n">speed_of_light</span><span class="p">,</span> <span class="n">meter</span><span class="o">/</span><span class="n">second</span><span class="p">)</span>
<span class="go">299792458*meter/second</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">convert_to</span><span class="p">(</span><span class="n">day</span><span class="p">,</span> <span class="n">second</span><span class="p">)</span>
<span class="go">86400*second</span>
<span class="gp">&gt;&gt;&gt; </span><span class="mi">3</span><span class="o">*</span><span class="n">newton</span>
<span class="go">3*newton</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">convert_to</span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">newton</span><span class="p">,</span> <span class="n">kilogram</span><span class="o">*</span><span class="n">meter</span><span class="o">/</span><span class="n">second</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
<span class="go">3*kilogram*meter/second**2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">convert_to</span><span class="p">(</span><span class="n">atomic_mass_constant</span><span class="p">,</span> <span class="n">gram</span><span class="p">)</span>
<span class="go">1.660539060e-24*gram</span>
</pre></div>
</div>
<p>Conversion to multiple units:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">convert_to</span><span class="p">(</span><span class="n">speed_of_light</span><span class="p">,</span> <span class="p">[</span><span class="n">meter</span><span class="p">,</span> <span class="n">second</span><span class="p">])</span>
<span class="go">299792458*meter/second</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">convert_to</span><span class="p">(</span><span class="mi">3</span><span class="o">*</span><span class="n">newton</span><span class="p">,</span> <span class="p">[</span><span class="n">centimeter</span><span class="p">,</span> <span class="n">gram</span><span class="p">,</span> <span class="n">second</span><span class="p">])</span>
<span class="go">300000*centimeter*gram/second**2</span>
</pre></div>
</div>
<p>Conversion to Planck units:</p>
<div class="doctest highlight-default notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">convert_to</span><span class="p">(</span><span class="n">atomic_mass_constant</span><span class="p">,</span> <span class="p">[</span><span class="n">gravitational_constant</span><span class="p">,</span> <span class="n">speed_of_light</span><span class="p">,</span> <span class="n">hbar</span><span class="p">])</span><span class="o">.</span><span class="n">n</span><span class="p">()</span>
<span class="go">7.62963087839509e-20*hbar**0.5*speed_of_light**0.5/gravitational_constant**0.5</span>
</pre></div>
</div>
</dd></dl>

</section>
</section>


            <div class="clearer"></div>
          </div>
        </div>
      </div>
      <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="../../../index.html">
              <img class="logo" src="../../../_static/sympylogo.png" alt="Logo"/>
            </a></p>
  <h3><a href="../../../index.html">Table of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Physical quantities</a><ul>
<li><a class="reference internal" href="#module-sympy.physics.units.util">Conversion between quantities</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="unitsystem.html"
                        title="previous chapter">Units and unit systems</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="../hep/index.html"
                        title="next chapter">High energy physics</a></p>
  <div role="note" aria-label="source link">
    <h3>This Page</h3>
    <ul class="this-page-menu">
      <li><a href="../../../_sources/modules/physics/units/quantities.rst.txt"
            rel="nofollow">Show Source</a></li>
    </ul>
   </div>
<div id="searchbox" style="display: none" role="search">
  <h3 id="searchlabel">Quick search</h3>
    <div class="searchformwrapper">
    <form class="search" action="https://docs.sympy.org/latest/search.html" method="get">
      <input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
      <input type="submit" value="Go" />
    </form>
    </div>
</div>
<script>$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related" role="navigation" aria-label="related navigation">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../../../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../../../py-modindex.html" title="Python Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="../hep/index.html" title="High energy physics"
             >next</a> |</li>
        <li class="right" >
          <a href="unitsystem.html" title="Units and unit systems"
             >previous</a> |</li>
        <li class="nav-item nav-item-0"><a href="../../../index.html">SymPy 1.9 documentation</a> &#187;</li>
          <li class="nav-item nav-item-1"><a href="../../index.html" >SymPy Modules Reference</a> &#187;</li>
          <li class="nav-item nav-item-2"><a href="../index.html" >Physics</a> &#187;</li>
          <li class="nav-item nav-item-3"><a href="index.html" >Unit systems</a> &#187;</li>
        <li class="nav-item nav-item-this"><a href="#">Physical quantities</a></li> 
      </ul>
    </div>
    <div class="footer" role="contentinfo">
        &#169; Copyright 2021 SymPy Development Team.
      Last updated on Sep 30, 2021.
      Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 4.1.2.
    </div>
  </body>

<!-- Mirrored from docs.sympy.org/latest/modules/physics/units/quantities.html by HTTrack Website Copier/3.x [XR&CO'2014], Sat, 15 Jan 2022 03:27:50 GMT -->
</html>